package com.ny.dao.impl;

import com.ny.dao.AdminDao;
import com.ny.entity.Admin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDaoImpl implements AdminDao {

    private final Connection connection;

    public AdminDaoImpl(Connection connection) {
        this.connection = connection;
    }

    @Override
    public Admin getAdminByCredentials(String adminName, String adminPassword) throws SQLException {
        String sql = "SELECT * FROM admins WHERE admin_name = ? AND admin_password = ?";
        try (PreparedStatement statement = connection.prepareStatement(sql)) {
            statement.setString(1, adminName);
            statement.setString(2, adminPassword);
            try (ResultSet resultSet = statement.executeQuery()) {
                if (resultSet.next()) {
                    Admin admin = new Admin();
                    admin.setAdminName(resultSet.getString("admin_name"));
                    admin.setAdminPassword(resultSet.getString("admin_password"));
                    return admin;
                }
            }
        }
        return null;
    }
}
